package com.ming.springboot.config;

import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by mqsi on 2022/5/13 19:30
 */
@ControllerAdvice(basePackages = "com.ming.springboot.controller")
public class MyGlobalDataHandler {

	@ModelAttribute(name = "md")
	public Map<String, Object> mydata(){
		HashMap<String, Object> map = new HashMap<>();
		map.put("address", "上海虹口区四川北路街道");
		map.put("gender", "男");
		return map;
	}

	@InitBinder("b")
	public void b(WebDataBinder binder){
		binder.setFieldDefaultPrefix("b.");
	}

	@InitBinder("a")
	public void a(WebDataBinder binder){
		binder.setFieldDefaultPrefix("a.");
	}
}
